import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author zyj
 * @date 2022年06月11日 9:16
 * 操作IP号
 */
public class InetAddressDemo {
    public static void main(String[] args) {
        try {
            InetAddress address = InetAddress.getByName("www.baidu.com");
            System.out.println(address.getHostAddress());//ip地址
            System.out.println(address.isReachable(1));
            InetAddress local = InetAddress.getLocalHost();
            System.out.println(local.getHostName());//主机名

            System.out.println(local.getHostAddress());
            //本机的ip号：localhost  /  127.0.0.1
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
